/**
 * 
 */
package org.chengsen.app;

import java.sql.Date;

import org.chengsen.config.AppConfig;
import org.chengsen.config.DataSourceConfig;
import org.chengsen.dao.UserDAO;
import org.chengsen.dataobject.UserDO;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author Jason.zhang
 * 
 */
public class AppMain {

	public static void main(String[] args) {
		testDAO();
	}

	public static void testDataSource() {
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
		ctx.register(DataSourceConfig.class);
		ctx.refresh();
		String driverClassName = (String) ctx.getBean("driverClassName");
		System.out.println(driverClassName);

	}

	public static void testDAO() {
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
		ctx.register(AppConfig.class);
		ctx.refresh();
		UserDAO userDAO = (UserDAO) ctx.getBean("userDAO");
		UserDO userDO = new UserDO();
		userDO.setBirthDate(new Date(System.currentTimeMillis()));
		userDO.setCellphone("0221062008");
		userDO.setFirstname("chengsen");
		userDO.setLastname("zhang");
		userDAO.addUser(userDO);
		System.out.println(userDAO);
		System.out.println(userDAO.getUser(0));
	}
}
